# - Find Windows Platform SDK
# Find the Windows includes
#
#  WINSDK_INCLUDE_DIR - where to find Windows.h
#  WINSDK_INCLUDE_DIRS - where to find all Windows headers
#  WINSDK_LIBRARY_DIR - where to find libraries
#  WINSDK_FOUND       - True if Windows SDK found.


# TODO: add the possibility to use a specific Windows SDK

IF(MSVC11)
  GET_FILENAME_COMPONENT(WINSDK8_DIR  "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\v8.0;InstallationFolder]" ABSOLUTE CACHE)
  GET_FILENAME_COMPONENT(WINSDK8_VERSION "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\v8.0;ProductVersion]" NAME)

  IF(WINSDK8_DIR)
    IF(NOT WindowsSDK_FIND_QUIETLY)
      MESSAGE(STATUS "Found Windows SDK ${WINSDK8_VERSION} in ${WINSDK8_DIR}")
    ENDIF(NOT WindowsSDK_FIND_QUIETLY)
    IF(TARGET_ARM)
      SET(WINSDK8_SUFFIX "arm")
    ELSEIF(TARGET_X64)
      SET(WINSDK8_SUFFIX "x64")
    ELSEIF(TARGET_X86)
      SET(WINSDK8_SUFFIX "x86")
    ENDIF(TARGET_ARM)
  ENDIF(WINSDK8_DIR)
ENDIF(MSVC11)

GET_FILENAME_COMPONENT(WINSDK71_DIR  "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\v7.1;InstallationFolder]" ABSOLUTE CACHE)
GET_FILENAME_COMPONENT(WINSDK71_VERSION "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\v7.1;ProductVersion]" NAME)

IF(WINSDK71_DIR)
  IF(NOT WindowsSDK_FIND_QUIETLY)
    MESSAGE(STATUS "Found Windows SDK ${WINSDK71_VERSION} in ${WINSDK71_DIR}")
  ENDIF(NOT WindowsSDK_FIND_QUIETLY)
ENDIF(WINSDK71_DIR)

GET_FILENAME_COMPONENT(WINSDKCURRENT_DIR  "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows;CurrentInstallFolder]" ABSOLUTE CACHE)
GET_FILENAME_COMPONENT(WINSDKCURRENT_VERSION "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows;CurrentVersion]" NAME)

IF(WINSDKCURRENT_DIR)
  IF(NOT WindowsSDK_FIND_QUIETLY)
    MESSAGE(STATUS "Found Windows SDK ${WINSDKCURRENT_VERSION} in ${WINSDKCURRENT_DIR}")
  ENDIF(NOT WindowsSDK_FIND_QUIETLY)
ENDIF(WINSDKCURRENT_DIR)

FIND_PATH(WINSDK_INCLUDE_DIR Windows.h
  HINTS
  ${WINSDK8_DIR}/Include/um
  ${WINSDK71_DIR}/Include
  ${WINSDKCURRENT_DIR}/Include
)

FIND_PATH(WINSDK_SHARED_INCLUDE_DIR d3d9.h
  HINTS
  ${WINSDK8_DIR}/Include/shared
  ${WINSDK71_DIR}/Include
  ${WINSDKCURRENT_DIR}/Include
)

FIND_PATH(WINSDK_LIBRARY_DIR ComCtl32.lib
  HINTS
  ${WINSDK8_DIR}/Lib/win8/um/${WINSDK8_SUFFIX}
  ${WINSDK71_DIR}/Lib
  ${WINSDKCURRENT_DIR}/Lib
)

FIND_PROGRAM(WINSDK_SIGNTOOL signtool
  HINTS
  ${WINSDK8_DIR}/Bin/x86
  ${WINSDK71_DIR}/Bin
  ${WINSDKCURRENT_DIR}/Bin
)

IF(WINSDK_INCLUDE_DIR)
  SET(WINSDK_FOUND TRUE)
  SET(WINSDK_INCLUDE_DIRS ${WINSDK_INCLUDE_DIR} ${WINSDK_SHARED_INCLUDE_DIR})
ELSE(WINSDK_INCLUDE_DIR)
  IF(NOT WindowsSDK_FIND_QUIETLY)
    MESSAGE(STATUS "Warning: Unable to find Windows SDK!")
  ENDIF(NOT WindowsSDK_FIND_QUIETLY)
ENDIF(WINSDK_INCLUDE_DIR)
